package b2.widget.room
{
	import b2.config.*;
	import b2.net.*;
	import b2.player.*;
	import b2.scene.*;
	import b2.util.*;
	import b2.widget.*;
	import b2.widget.tab.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;

	public class RoomPlayerItem extends Sprite
	{
		public var playerId:int;
		public var tankId:int;
		private var _occupied:Boolean;
		private var titleText:TextField;
		private var levelText:TextField;
		private var tankIcon:Sprite;
		
		public function RoomPlayerItem(forbidden:Boolean = false)
		{
			super();
			//背景框
			var RoomPlayerItemBgr:Class = ResourceHelper.getInstance().getClassByName("RoomPlayerItemBgr");
			var roomPlayerItemBgr:Sprite = new RoomPlayerItemBgr();
			addChild(roomPlayerItemBgr);
			//禁用标志
			var UnavailableBgr:Class = ResourceHelper.getInstance().getClassByName("EquipSlotBgr2");
			var unavailableBgr:Sprite = new UnavailableBgr();
			unavailableBgr.width = 40;
			unavailableBgr.height = 40;
			unavailableBgr.x = 12;
			unavailableBgr.y = 10;
			unavailableBgr.alpha = 0.2;
			unavailableBgr.visible = forbidden;
			addChild(unavailableBgr);
			//名字
			titleText = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.CENTER;
			titleText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000);
			titleText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			titleText.x = 38;
			titleText.y = 66;
			addChild(titleText);
			//等级
			levelText = new TextField();
			levelText.selectable = false;
        	levelText.autoSize = TextFieldAutoSize.LEFT;
			levelText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0xFFFF000, true);
//			levelText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			levelText.x = 40;
			levelText.y = 0;
			addChild(levelText);
		}
		
		public function get occupied():Boolean
		{
			return _occupied;
		}
		
		public function loadEnemy(enemyIndex:int, level:int):void
		{
			this.playerId = -1;
			this.tankId = -1;
			_occupied = true;
			levelText.text = "Lv." + level;
			var enemyConfig:EnemyConfig = Config.enemyConfigs[enemyIndex];
			//玩家名字
			titleText.text = enemyConfig.name;
			//坦克图片
			var tankConfig:TankConfig = Config.objectConfigs[enemyConfig.tankIndex];
			var TankIcon:Class = ResourceHelper.getInstance().getClassByName(tankConfig.iconImage);
			tankIcon = new TankIcon();
			tankIcon.filters = [new ColorMatrixFilter(enemyConfig.filter)];
			tankIcon.x = 10;
			tankIcon.y = 10;
			//齐天大圣
			if (enemyConfig.tankIndex == 10015)
			{
				tankIcon.width = 74.25;
				tankIcon.height = 83.25;
			}
			//死亡骑士
			else if (enemyConfig.tankIndex == 10020)
			{
				tankIcon.width = 65;
				tankIcon.height = 65;
			}
			else
			{
				tankIcon.width = 54;
				tankIcon.height = 54;
			}
			addChild(tankIcon);
		}
		
		public function loadPlayer(playerId:int, playerName:String, tankId:int, tankIndex:int):void
		{
			this.playerId = playerId;
			this.tankId = tankId;
			_occupied = true;
			//玩家名字
			titleText.text = playerName;
			//坦克图片
			var tankConfig:TankConfig = Config.objectConfigs[tankIndex];
			var TankIcon:Class = ResourceHelper.getInstance().getClassByName(tankConfig.iconImage);
			tankIcon = new TankIcon();
			tankIcon.x = 10;
			tankIcon.y = 10;
			//齐天大圣
			if (tankIndex == 10015)
			{
				tankIcon.width = 74.25;
				tankIcon.height = 83.25;
			}
			//死亡骑士
			else if (tankIndex == 10020)
			{
				tankIcon.width = 65;
				tankIcon.height = 65;
			}
			else
			{
				tankIcon.width = 54;
				tankIcon.height = 54;
			}
			addChild(tankIcon);
		}
		
		public function removePlayer():void
		{
			playerId = 0;
			_occupied = false;
			titleText.text = "";
			if (tankIcon != null && tankIcon.parent != null)
			{
				tankIcon.parent.removeChild(tankIcon);
				tankIcon = null;
			}
		}
		
	}
}